function ChessBox(el,options={})
{
    this.el=document.querySelector(el)
    this.results = [
        ['','','','','',  '','','','','', '','','','','',],
        ['','','','','',  '','','','','', '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
    
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
    
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
        ['','','','','',  '','','','','',  '','','','','',],
    ]
    this.targetObj = null
    this.colorArr = ['black', 'white']
   
    this.colorIndex = null // 

    this.init()
}
ChessBox.prototype.init=function(){
    //生成棋盘
    this.create()

    //下棋
    this.start()
    //悔棋
    this.regret()

    // this.random()
}
ChessBox.prototype.create=function(){
    let num = 0
    for (let row = 0; row < 15; row++) 
    {
        let rowObj = document.createElement("div");
        rowObj.className = 'row'
    
        for (let col = 0; col < 15; col++) 
        {
            num++
            let colObj = document.createElement("div");
            colObj.className = 'col'
            colObj.innerText = num
            rowObj.appendChild(colObj)
    
            // --------------------------
            colObj.setAttribute('row', row)
            colObj.setAttribute('col', col)
            // --------------------------
        }
    
        this.el.appendChild(rowObj)
    }
}

ChessBox.prototype.random=function(max,min){
    return Math.floor(Math.random()*(max-min+1)+min)
}
ChessBox.prototype.start=function(){
    this.el.onclick =(evt)=>{
        let e = evt || window.event
        let target = e.target || e.srcElement
        this.colorIndex = this.random(1,0) // 随机先手：0-黑，1-白
        // 避免重复下棋
        if (target.className.includes('col ')) return
    
        // 下棋
        target.className = `col ${this.colorArr[this.colorIndex]}` 
    
        // --------------------------
        console.log(this.results);
        
        let rowI = target.getAttribute('row')
        let colI = target.getAttribute('col')
        this.results[rowI][colI] = this.colorArr[this.colorIndex]
    
        this.colorIndex = Number(!this.colorIndex)  // 重置棋子颜色  黑之后白 白之后黑
        this.targetObj  = target // 保存最后点击盒模型 可以悔棋
    }
    
}
ChessBox.prototype.regret=function(){
    this.el.oncontextmenu =(evt)=> {
        let e  = evt || window.event
        e.preventDefault() 

        this.targetObj.className ='col'

        this.colorIndex = Number(!this.colorIndex)  // 悔棋后还是之前的棋子

        let rowI = this.targetObj .getAttribute('row')
        let colI = this.targetObj .getAttribute('col')
        this.results[rowI][colI] = ''
        console.log('最新结果：',this.results);
    }
}